/**
 * 
 */
package co.edu.eam.iso.enums;

import java.math.BigDecimal;

import co.edu.eam.iso.util.BigDecimalUtil;
import co.edu.eam.iso.util.MessagesUtil;

/**
 * @author Giovanny Ramirez Blandon
 * @version 1.0
 */
public enum RankEnum {
	
	BAD         (BigDecimal.valueOf(0.00), BigDecimal.valueOf(40.00),  "label.rank.bad"), 
	REGULAR     (BigDecimal.valueOf(40.1), BigDecimal.valueOf(60.00),  "label.rank.regular"),
	ACCEPTABLE  (BigDecimal.valueOf(60.1), BigDecimal.valueOf(80.00),  "label.rank.acceptable"),
	EXCELLENT   (BigDecimal.valueOf(80.1), BigDecimal.valueOf(100.1), "label.rank.excellent");

	private BigDecimal minValue;
	private BigDecimal maxValue;
	private String keyMessage;
	
	private RankEnum(BigDecimal minValue, BigDecimal maxValue, String keyMessage) {
		this.minValue = minValue;
		this.maxValue = maxValue;
		this.keyMessage = keyMessage;
	}

	/**
	 * @return the minValue
	 */
	public BigDecimal getMinValue() {
		return minValue;
	}

	/**
	 * @param minValue the minValue to set
	 */
	public void setMinValue(BigDecimal minValue) {
		this.minValue = minValue;
	}

	/**
	 * @return the maxValue
	 */
	public BigDecimal getMaxValue() {
		return maxValue;
	}

	/**
	 * @param maxValue the maxValue to set
	 */
	public void setMaxValue(BigDecimal maxValue) {
		this.maxValue = maxValue;
	}

	/**
	 * @return the keyMessage
	 */
	public String getKeyMessage() {
		return keyMessage;
	}

	/**
	 * @param keyMessage the keyMessage to set
	 */
	public void setKeyMessage(String keyMessage) {
		this.keyMessage = keyMessage;
	}

	public String toString() {
		return MessagesUtil.getMessage(this.getKeyMessage());
	}
	
	public static RankEnum determinateRank(BigDecimal quality) {
		for (RankEnum rank : values()) {
			if (BigDecimalUtil.between(quality, rank.getMinValue(),
					rank.getMaxValue())) {
				return rank;
			}
		}

		return null;
	}
	
}
